//
//  TransferCell.m
//  CBT
//
//  Created by Mr.Zhang on 2019/3/12.
//  Copyright © 2019 Mr.Zhang. All rights reserved.
//

#import "TransferCell.h"

@interface TransferCell()

@property (weak, nonatomic) IBOutlet UILabel *ethAddressLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *amountLabel;
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;

@property (weak, nonatomic) IBOutlet UIImageView *layerImageView;

@end

@implementation TransferCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.layerImageView.image = [UIImage resizableImageWithName:@"huijiao"];
}

- (IBAction)copyAction:(UIButton *)sender {
    [HFStatusView showSuccessMessage:kLocalizedString(@"复制成功",nil)];
    UIPasteboard *pboard = [UIPasteboard generalPasteboard];
    pboard.string = [NSObject dx_isNullOrNilWithObject:self.model] ? self.withdrawModel.account : self.model.address;
}

-(void)setModel:(TransferItemModel *)model {
    
    _model = model;
    
    self.ethAddressLabel.text = model.address;
    self.timeLabel.text   = [NSString getShowDateMonthDayWithTime:[model.createDate longLongValue]];
    self.amountLabel.text = [NSString stringWithFormat:@"-%@ %@",[DecimalNumberTool formatNumberWithString:model.amount isAssets:YES],self.symbol];
    self.statusLabel.text = [self getStatusLabelTextWithStatus:model.status];
    self.statusLabel.textColor = UIColorFromRGB(0x999999);
    self.amountLabel.textColor = [self getStatusLabelTextColorWithStatus:model.status];
}

-(void)setWithdrawModel:(WithdrawItemListModel *)withdrawModel {
    
    _withdrawModel = withdrawModel;
    
    self.ethAddressLabel.text = withdrawModel.account;
    self.timeLabel.text   = [NSString getShowDateMonthDayWithTime:[withdrawModel.drawDate longLongValue]];
    self.amountLabel.text = [NSString stringWithFormat:@"-%@ %@",[DecimalNumberTool formatNumberWithString:withdrawModel.amount isAssets:YES],self.symbol];
    self.statusLabel.text = [self getStatusLabelTextWithStatus:withdrawModel.status];
    self.statusLabel.textColor = UIColorFromRGB(0x999999);
    self.amountLabel.textColor = [self getStatusLabelTextColorWithStatus:withdrawModel.status];
}

- (NSString *)getStatusLabelTextWithStatus:(NSString *)status {
    NSString *head = @"转账";
    if (self.showListType == 2) {
        head = @"划转";
    }
    if ([status integerValue] == -1) {
        head = [NSString stringWithFormat:@"%@确认中",head];
        return kLocalizedString(head,nil);
    }
    else if ([status integerValue] == 1) {
        head = [NSString stringWithFormat:@"%@成功",head];
        return kLocalizedString(head,nil);
    }
    else if ([status integerValue] == 2) {
        return kLocalizedString(@"打包中",nil);
    }
    else {
        head = [NSString stringWithFormat:@"%@失败",head];
        return kLocalizedString(head,nil);
    }
}

- (UIColor *)getStatusLabelTextColorWithStatus:(NSString *)status {
    if ([status integerValue] == -1 || [status integerValue] == 2) {
        return UIColorFromRGB(0xECBF23);
    }
    else if ([status integerValue] == 1) {
        return UIColorFromRGB(0x00A200);
    }
    else {
        return UIColorFromRGB(0xFF646F);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
